package com.tianruan.dc.common.utils;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.io.Serializable;
import java.util.List;

/**
 * @Author: Dong
 * @Email: dong980514280@gmail.com
 * @Create: 2021-12-21 09:57
 * @PS 分页工具类
 */
@Data
public class PageUtils implements Serializable {
	private static final long serialVersionUID = 1L;
	//总记录数
	private long total;
	//每页记录数
	private long pageSize;
	//总页数
	private long totalPage;
	//当前页数
	private long current;
	//列表数据
	private List<?> list;
	
	/**
	 * 分页
	 * @param list        列表数据
	 * @param total  总记录数
	 * @param pageSize    每页记录数
	 * @param current    当前页数
	 */
	public PageUtils(List<?> list, long total, long pageSize, long current) {
		this.list = list;
		this.total = total;
		this.pageSize = pageSize;
		this.current = current;
		this.totalPage = (int)Math.ceil((double)total / pageSize);
	}

	public PageUtils(IPage<?> page) {
		this.list = page.getRecords();
		this.total = page.getTotal();
		this.pageSize = page.getSize();
		this.current = page.getCurrent();
		this.totalPage = (int)Math.ceil((double)this.total / this.pageSize);
	}
	
}
